package com.masterclient.app.modules.main;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.masterclient.app.BaseActivity;
import com.masterclient.app.R;
import com.masterclient.app.widget.TitlebarView;


public class PrivacyWebActivity extends BaseActivity {

    private WebView dwebView;
    private TitlebarView title_view;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_privacy_web);

        dwebView = findViewById(R.id.dwebview);
        title_view = findViewById(R.id.title_view);

        WebSettings webSettings = dwebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setSupportZoom(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setDisplayZoomControls(false);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webSettings.setAllowFileAccess(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setLoadsImagesAutomatically(true);
        webSettings.setDefaultTextEncodingName("utf-8");
        webSettings.setUserAgentString(webSettings.getUserAgentString() + " app:xrk");
        init();
    }

    private void init() {
        String url = getBundleString("url");
        String title = getBundleString("title");

        title_view.setRightVisible(View.GONE);
        title_view.setOnViewClick(new TitlebarView.onViewClick() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });
        if (!TextUtils.isEmpty(title)) {
            title_view.setTitle(title);
        }
        dwebView.loadUrl(url);
    }
}
